﻿<%@ Page Title="stock" Language="C#" MasterPageFile="~/EasyUI.master" AutoEventWireup="true" CodeBehind="List.aspx.cs" Inherits="jnxc.Web.stock.List" %>
<asp:Content ID="Content1" ContentPlaceHolderID="head" runat="server">

     <script type="text/javascript">
         $(function () {
             InitGird();
             InitSearch();
         });
         //初始化表格
         function InitGird() {
             $('#tt').datagrid({
                 title: '物品列表', //表格标题
                 url: 'GetStock.ashx', //请求数据的页面
                 sortName: 'mname', //排序字段
                 idField: 'stockid', //标识字段,主键
                 iconCls: '', //标题左边的图标
                 width: '100%', //宽度
                 //height: $(parent.document).find("#mainPanle").height() - 35 > 0 ? $(parent.document).find("#mainPanle").height() - 35 : 500, //高度
                 nowrap: false, //是否换行，True 就会把数据显示在一行里
                 striped: true, //True 奇偶行使用不同背景色
                 collapsible: false, //可折叠
                 sortOrder: 'desc', //排序类型
                 remoteSort: true, //定义是否从服务器给数据排序
                 fitColumns: true,
                 method: 'post',
                 columns: [[                     
                     { title: '编号', field: 'mbh', width: 150, sortable: true },
                     { title: '名称', field: 'mname', width: 150 },
                     { title: '型号', field: 'mtype', width: 120 },
                     { title: '库存', field: 'snums', width: 150 },                     
                     {
                         title: '操作', field: 'mid', width: 80, formatter: function (value, row, index) {
                             return '<a style="color:red" href="javascript:" onclick="inData(' + value + ',0,' + row.snums + ');$(this).parent().click();return false;">入库</a> <a style="color:red" href="javascript:" onclick="inData(' + value + ',1,' + row.snums + ');$(this).parent().click();return false;">出库</a>';
                         }
                     }
                 ]],
                 toolbar: "#tab_toolbar",
                 queryParams: { "action": "query" },
                 pagination: true, //是否开启分页
                 pageNumber: 1, //默认索引页
                 pageSize: 20, //默认一页数据条数
                 rownumbers: true //行号
             });


         }
         //初始化搜索框
         function InitSearch() {
             $("#ipt_search").searchbox({
                 width: 200,
                 //iconCls: 'icon-save',
                 searcher: function (val, name) {
                     $('#tt').datagrid('options').queryParams.search_type = name;
                     $('#tt').datagrid('options').queryParams.search_value = val;
                     $('#tt').datagrid('reload');
                 },
                 prompt: '请输入查询信息'
             });
         }
         function inData(inmid,type,snums) {
             $('#midin').val(inmid);
             $("#mytype").val(type);
             if (type == 0)
             {
                 $("#snum").numberbox({
                     min: 0,                     
                     precision: 2
                 });                 
                 $('#dlgin').dialog('open').dialog('setTitle', '入库');
             }
                 
             else
             {                
                 $("#snum").numberbox({    
                     min:0,
                     max:snums,
                     precision:2    
                 });  

                 $('#dlgin').dialog('open').dialog('setTitle', '出库');
             }              

         }
        
         function saveNum() {
             var otype = $("#mytype").val();
             if(otype=="0")
             $('#fmin').form('submit', {
                 url: "../materialinfo/GetMaterial.ashx?action=instock",
                 onSubmit: function () {
                     return $(this).form('validate');
                 },
                 success: function (result) {
                     if (result.indexOf("T") == 0) {
                         $('#dlgin').dialog('close');
                         $('#tt').datagrid('clearSelections');
                         $.messager.alert("提示", "恭喜您，入库成功", "info");
                         $('#tt').datagrid('reload');

                     }
                     else if ((result.indexOf("F") == 0)) {
                         $.messager.alert("提示", "入库失败，请重新操作！", "info");
                         return;
                     }
                     else if ((result.indexOf("L") == 0)) {
                         $.messager.alert("提示", "长时间没有操作，请重新登录！", "info");
                         top.location = '/index.aspx';
                         return;
                     }
                 }
             });
             else
                 $('#fmin').form('submit', {
                     url: "../materialinfo/GetMaterial.ashx?action=outstock",
                     onSubmit: function () {
                         return $(this).form('validate');
                     },
                     success: function (result) {
                         if (result.indexOf("T") == 0) {
                             $('#dlgin').dialog('close');
                             $('#tt').datagrid('clearSelections');
                             $.messager.alert("提示", "恭喜您，出库成功", "info");
                             $('#tt').datagrid('reload');

                         }
                         else if ((result.indexOf("F") == 0)) {
                             $.messager.alert("提示", "出库失败，请重新操作！", "info");
                             return;
                         }
                         else if ((result.indexOf("L") == 0)) {
                             $.messager.alert("提示", "长时间没有操作，请重新登录！", "info");
                             top.location = '/index.aspx';
                             return;
                         }
                     }
                 });


         }
         function tindate() {

             var row = $('#tt').datagrid('getSelected');
             if (row == null) {
                 $.messager.alert("提示", "请选择要修改的行！", "info");
             }
             if (row)
             {
                 inData(row.mid, 0, 0);
             }
         }
         function toutdate() {

             var row = $('#tt').datagrid('getSelected');
             if (row == null) {
                 $.messager.alert("提示", "请选择要修改的行！", "info");
             }
             if (row) {
                 inData(row.mid, 1,row.snums);
             }
         }
       
    </script>
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" runat="server">
    <table id="tt">
    </table>
    <div id="tab_toolbar" style="padding: 4px;">
        <table cellpadding="0" cellspacing="0" style="width: 100%">
            <tr>

                <td style="padding-left: 2px">


                    <a href="#" onclick="tindate();" id="a_add"
                        class="easyui-linkbutton" iconcls="icon-add">入库</a>                   
                    <a href="#" onclick="toutdate();return false;" id="a_del" class="easyui-linkbutton" iconcls="icon-cancel">出库</a>

                </td>
                <td style="text-align: right; padding-right: 15px">
                    <input id="ipt_search" menu="#search_menu" />
                    <div id="search_menu" style="width: 120px">
                        <div name="usernum">
                            名 称
                        </div>
                        <div name="username">
                            编 号
                        </div>
                    </div>
                </td>
            </tr>
        </table>
    </div>    
    
     <div id="dlgin" class="easyui-dialog" style="width: 250px; height: auto; padding: 10px 20px"
        data-options="closed:true,buttons:'#in-buttons',shadow:false">       
        
        <form id="fmin" method="post">            
            <div class="fitem">
                <label>数量：</label>
                <input id="snum" name="snum" style="width:80px"  />
                <input name="mytype" id="mytype" type="hidden" />
                <input name="midin" id="midin" type="hidden" /> 
                <%--<input name="stocknum" id="stocknum" type="hidden" /> --%>              
            </div> 
        </form>
    </div>
    <div id="in-buttons">
        <a href="#" class="easyui-linkbutton" data-options="iconCls:'icon-ok'" onclick="saveNum()">保存</a>
        <a href="#" class="easyui-linkbutton" data-options="iconCls:'icon-cancel'" onclick="javascript:$('#dlgin').dialog('close')">关闭</a>
    </div>
</asp:Content>